import http from '@/core/request/request.ts'

const CRUD = (path) => {
  return {
    // 新增
    create: async function (data, config = {}) {
      return await http.post(path, data)
    },
    // 删除
    delete: async function (data, config = {}) {
      return await http.delete(`${path}/${data.id}`)
    },
    // 更新
    update: async function (data, config = {}) {
      return await http.put(`${path}/${data.id}`, data)
    },
    // 列表
    list: async function (params, config = {}) {
      return await http.get(path, params)
    },
    // 详情
    read: async function (params, config = {}) {
      return await http.get(`${path}/${params.id}`, params)
    },
  }
}

export default CRUD
